<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Mtrade extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    
    public function getIndex($number = 0,$offset = 0)
    {
        $limit = $offset ? intval($offset) : '0';
        
        $sql = "SELECT lt.*,u.username FROM logTrade AS lt LEFT JOIN user AS u ON lt.id_user = u.id ORDER BY lt.id DESC";
        
        $count = $this->db->query($sql)->num_rows();
        if($offset >= $count && $count != 0){
            $this->load->view('template/404',$this->data);
            return false;
        }
        
        $xdata = " LIMIT ".$limit.",".$number." ";
        $xs = $this->db->query($sql.$xdata)->result_object();
        return array('data' => $xs, 'count' => $count);
    }
    
    public function getSearchAjax($key)
    {
        $sql = "SELECT lt.*,u.username FROM logTrade AS lt LEFT JOIN user AS u ON lt.id_user = u.id WHERE lt.codeTrade = '".$key."'";
        $data = $this->db->query($sql)->result_object();
        //die(print_r($data));
        return $data;
    }
}